package cn.bjxy.shishaolong.talk_room.server.entity;

/**
 * 用户信息实体
 * 
 * 因为考虑到了要使用set集合存储，所以重写了hashCode()方法，和 equals()方法
 * 
 * @author long
 *
 */
public class User {

	private static int counter = 0;
	private final int id = counter++;

	private IpAndPort ipAndPort;
	
	private String name;
//	private String ip;
//	private int port;
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	/*public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}*/

	/*public String getUserInfo() {
		return name+"("+ip+":"+port+")";
	}
	
	public boolean isIpAndPort(String ip, int port) {
		return this.ip.equals(ip) && this.port==port;
	}*/
	
	@Override
	public int hashCode() {

		int result = 17;
		result = 37*result + counter;
		result = 37*result + id;
//		result = 37*result + ip.hashCode();
//		result = 37*result + port;
//		result = 37*result + name.hashCode();
		result = 37*result + (ipAndPort==null? 0 :ipAndPort.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		return obj instanceof User &&
				ipAndPort.equals(((User)obj).ipAndPort);
//				id == ((User)obj).id &&
//				ip.equals(((User)obj).ip) &&
//				port == (((User)obj).port);
//				name.equals(((User)obj).name)
	}
	public IpAndPort getIpAndPort() {
		return ipAndPort;
	}
	public void setIpAndPort(IpAndPort ipAndPort) {
		this.ipAndPort = ipAndPort;
	}
	@Override
	public String toString() {
		return name+"(" + ipAndPort + ")";
	}
}
